package com.tool.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tool.entity.User;
import com.tool.mapper.UserMapper;
import com.tool.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author niuyicong
 * @date 2024/11/8  23:45:48
 * @description
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/page")
    public IPage<User> page(){
        IPage<User> page = new Page<>(1,3);
        IPage<User> resultPage = userMapper.selectPage(page,null);
        //Page<User> userIPage = userMapper.selectPage(page, null);
        return resultPage;
    }

    @GetMapping("/allUser")
    public List<User> allUser(){
        List<User> users = userService.allUser();
        return users;
    }
    @GetMapping("getUserById")
    public User getUserById(Long userId){
        User user = userService.getUserById(userId);
        return user;
    }
    @PostMapping("/getUserByIds")
    public List<User> getUserByIds(@RequestBody List<Long> ids){
        List<User> users = userService.getUserByIds(ids);
        return users;
    }

    @PostMapping("/update")
    public void update(@RequestBody User user){
        userService.update(user);
    }

    @PostMapping("/insert")
    public void insert(@RequestBody User user){
        userService.insert(user);
    }

    @PostMapping("/batchInsert")
    public void batchInsert(@RequestBody List<User> list){
        userService.batchInsert(list);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody Long userId){
        userService.delete(userId);
    }

    @PostMapping("/batchDelete")
    public void batchDelete(@RequestBody List<Long> ids){
        userService.batchDelete(ids);
    }



}
